<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
	request.setAttribute("path", basePath);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<!--jsonp跨域请求  -->
	<script type="text/javascript">
    function doSomething(data) {
        // 对data处理
        console.log(data);
    }
    var script = document.createElement("script");
    script.src = "<%=basePath%>/json.do?callback=doSomething";
    document.body.appendChild(script);

    // 1.生成一个script标签，将其append在body上，向服务器发出请求
    // 2.服务器根据 callback 这个参数生成一个包含数据的函数 doSomething({"a", "1"})
    // 3.页面事先已声明doSomething函数，此时执行 doSomething(data) 这个函数，获得数据
	
    </script>
</body>
</html>